home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 44 / Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso / -in_the_mag- / basics / blitz / methodbblib.lha / MethodBBLib / Examples / DTSoundExample.asc < prev    next >
Text File  |  1997-07-27  |  2KB  |  101 lines

  1. ;Structures
  2.  
  3. ;***** datatypes/soundclass.h *****
  4.  
  5. NEWTYPE.VoiceHeader
  6.  vh_OneShotHiSamples.l
  7.  vh_RepeatHiSamples.l
  8.  vh_SamplesPerHiCycle.l
  9.  vh_SamplesPerSec.w
  10.  vh_Octaves.b
  11.  vh_Compression.b
  12.  vh_Volume.l
  13. End NEWTYPE
  14.  
  15.  
  16. ;Defines
  17.  
  18. ;***** datatypes/datatypesclass.h *****
  19.  
  20. #DTA_Dummy=((1LSL31)+$1000)
  21. #DTA_SourceType=(#DTA_Dummy+101)
  22. #DTA_GroupID=(#DTA_Dummy+31)
  23.  
  24. #DTST_FILE=2
  25.  
  26. #DTM_TRIGGER=($631)
  27.  
  28. #STM_PLAY=2
  29.  
  30. ;***** datatypes/datatypes.h *****
  31.  
  32. #GID_SOUND=$73 6F 75 6E
  33.           ;  s  o  u  n
  34.  
  35. ;***** datatypes/soundclass.h *****
  36.  
  37. #SDTA_Dummy=(#DTA_Dummy+500)
  38. #SDTA_VoiceHeader=(#SDTA_Dummy+1)
  39. #SDTA_Sample=(#SDTA_Dummy+2)
  40. #SDTA_SampleLength=(#SDTA_Dummy+3)
  41. #SDTA_Volume=(#SDTA_Dummy+5)
  42. #SDTA_Cycles=(#SDTA_Dummy+6)
  43.  
  44. ;***** *****
  45.  
  46. DEFTYPE.VoiceHeader *vhdr     ;VoiceHeader allows to get infos about sound
  47. DEFTYPE.l sample,samplelength
  48.  
  49. MaxLen name$=120
  50. Dim *args.b(1)
  51.  
  52. ;We read the args
  53.  
  54. rdargs.l=ReadArgs_("/A",&*args(0),0)
  55.  
  56. If rdargs=0           ;No args ???
  57.  NPrint "No Args !!"
  58.  End                  ;YES => End
  59. EndIf
  60.                       ;NO => Continue
  61.  
  62. name$=Peek$(*args(0)) ;Get the filename from the read args
  63.  
  64. FreeArgs_ rdargs
  65.  
  66. ;We define the tags for the DTObject creation
  67. ;#DTA_SourceType : #DTST_FILE - The object is a file (it could be ram or
  68. ;clipboard)
  69. ;#DTA_GroupID : #GID_SOUND - We only want a sound (not a picture, a text or
  70. ;an anim
  71. ;#SDTA_Volume : 64 - We set the volume to 64 (maximum)
  72. ;#STDA_Cycles : 1 - Only one time
  73.  
  74. *o.b=NewDTObjectA_(&name$,VarArgs(#DTA_SourceType,#DTST_FILE,#DTA_GroupID,#GID_SOUND,#SDTA_Volume,64,#SDTA_Cycles,1,0))
  75. ;We make it
  76.  
  77. If *o=0  ;ERROR ???
  78.  NPrint name$," : DTObject creation failed !!"
  79.  End     ;YES=> End
  80. EndIf
  81.  
  82. ;We get attrs from the DTObject
  83. ;#SDTA_VoiceHeader : &*vhdr - We get the VoiceHeader structure in order to
  84. ;have some infos on the sound (Samples per second ,...)
  85. ;#SDTA_Sample : &sample - We get the sample of the sound in the sample variable
  86. ;#SDTA_SampleLength : &samplelength - The Sample Length !
  87.  
  88. GetDTAttrsA_ *o,VarArgs(#SDTA_VoiceHeader,&*vhdr,#SDTA_Sample,&sample,#SDTA_SampleLength,&samplelength,0)
  89.  
  90. DoMethod *o,#DTM_TRIGGER,0,#STM_PLAY,0 ;We play the sound
  91.  
  92. leng.l=(((samplelength/*vhdr\vh_SamplesPerSec)*50)+50) ;Length of the sound in ticks
  93. lens.f=leng/50 ;Length of the sound in seconds
  94. NPrint name$," : ",lens," s" ;Display infos
  95.  
  96. Delay_ leng
  97.  
  98. DisposeDTObject_ *o  ;Free the DTObject
  99.  
  100. End ;FINISH !!!
  101.